/**
 * 查询菜单列表
 */
function listMenu(){
	var args = {
		formId:"myform",
        url: "/sys/index.do",
        callBack : function(response) {
			_setHtml("list_block", response);
		}
    };
    _ajaxSubmit(args);
}

/**
 * 显示菜单编辑页面
 * @param id 菜单主键
 * @param view 是否查看页面，true or false
 */
function editMenu(id,view){
	var args = {
		url: "/sys/menu.do",
	  	data: {"sid":id},
	  	isNew: _isNull(id),
	  	isView: view
	};
	_showEditForm(args);
}

/**
 * 删除菜单
 * @param sid 菜单ID
 */
function deleteMenu(sid){
	if(!_isNull(sid)){
		_checklist("sids" , false);
		_setElementAttr("sids_"+sid, "checked", true);
	}
	if(_getChecklist("sids").length==0){
		_showErrorMessage("请先选择想要删除的菜单！");
		return false;
	}
	_showConfirmMessage({
		text: "将会删除所选中的菜单，确定要继续吗？",
		okCallback : function() {
			var args = {
				formId: "myform",
				url: "/sys/menu.delete",
				callBack : function(){
					var sids = _getChecklist("sids").split(",");
		  			for(var i=0;i<sids.length;i++){
		  				delTreeTableNode("tr-"+sids[i]);
		  			}
				}
			};
			_ajaxSubmit(args);
		}
	});
}

/**
 * 移动菜单
 * @param type 移动类型，1为上移，-1为下移
 */
function moveMenu(type){
	var op = ((type==1)?"上移":"下移");
	if(_getChecklist("sids").length==0){
		_showErrorMessage("请先选择想要"+op+"的菜单！");
		return false;
	}
	var parentSid = _getCheckParentSid("sids");
	if(parentSid!=null&&parentSid.split(",").length>1){
		_showErrorMessage("上下移动菜单时，只能移动同一父菜单下的菜单！");
		return false;
	}
	if(parentSid!=null&&parentSid!="")parentSid=parentSid.substring(3);
	_showConfirmMessage({
		text: "所选中的菜单将会"+op+"一行，确定要继续吗？",
		okCallback : function() {
			var args = {
				formId: "myform",
				url: "/sys/menu.move",
			  	data: {type : type,parentSid:parentSid},
			  	callBack : function(){
			  		var sids = _getChecklist("sids").split(",");
		  			for(var i=0;i<sids.length;i++){
		  				if(type==1){
		  					moveTreeTableNode("tr-"+sids[i],'up');
		  				}else{
		  					moveTreeTableNode("tr-"+sids[i],'down');
		  				}
		  			}
			  	}
			};
			_ajaxSubmit(args);
		}
	});
}
